/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.uccart_project.controller;
/*tomala que es tuya*/
 
import com.uccart_project.model.Usuario;
import com.uccart_project.ui.forms.UI_Alumno;
import com.uccart_project.ui.forms.UI_Login_Nuevo;
import com.uccart_project.util.EntityManagerFactorySingleton;
import java.awt.CardLayout;
import java.util.List;
import javax.persistence.EntityManager;

/**
 *
 * @author KNO
 */
public class Controller_Application {
    
    public static final String PANEL_PRINCIPAL = "PanelPrincipal";
    public static final String PANEL_SELECCION_CURSO = "PanelSelecionCurso";
    public static final String PANEL_COBRO = "PanelCobro";
    public static final String PANEL_HISTORIAL = "PanelHistorial";
    public static final String PANEL_ESTADO_CUENTA = "PanelEstadoCuenta";
    public static final String PANEL_HORARIO = "PanelHorario";
    public static final String PANEL_INFORMACION = "PanelInformacion";
    
 
    private UI_Login_Nuevo uiLogin;
    private UI_Alumno uiAlumno;
    

    public Controller_Application() {
      
        uiLogin = new UI_Login_Nuevo(this);
        uiAlumno = new UI_Alumno(this);
         
    }

    public void iniciar() {
        uiLogin.setVisible(true); 
    }
    
    public void cerrarSession(){
        this.uiAlumno.dispose();
        this.uiLogin.setVisible(true);
        
    }
 
    public void mostrarMenuPrincipal() {
        this.uiLogin.dispose();
        this.uiAlumno.setVisible(true);
    }
    
    public void mostrarMatricula(){
        this.uiAlumno.cambiarPanel(PANEL_SELECCION_CURSO); 
    }
    
    public void mostrarCobro(){
        this.uiAlumno.cambiarPanel(PANEL_COBRO); 
    }
    
    public void mostrarEstadoCuenta(){
        this.uiAlumno.cambiarPanel(PANEL_ESTADO_CUENTA); 
    }
    
    public void mostrarHistorial(){
        this.uiAlumno.cambiarPanel(PANEL_HISTORIAL); 
    }
    
    public void mostrarHorario(){
        this.uiAlumno.cambiarPanel(PANEL_HORARIO); 
    }
     
    public void mostrarPanelPrincipal(){
        this.uiAlumno.cambiarPanel(PANEL_PRINCIPAL); 
    }
    
     public void mostrarPanelInformacion(){
        this.uiAlumno.cambiarPanel(PANEL_INFORMACION); 
    }
    
    
    
    
    public void verificarUsuario(String id, String password ) {

        System.out.println("verificarUsuario " + id + password );
        EntityManager em = EntityManagerFactorySingleton.getFactory().createEntityManager();
// Inicio de transacción
        em.getTransaction().begin();
        List result = em.createNamedQuery("Usuario.findByUsId").setParameter("usId", id).getResultList();
        em.getTransaction().commit();
        em.close();
        if (!result.isEmpty()) {
            System.out.println(((Usuario) result.get(0)).getUsPw());
            if (((Usuario) result.get(0)).getUsPw().equals(password)) {
                mostrarMenuPrincipal();
                System.out.println("sos un boludaso");
            }
        }
    }
}
